package orlowski.kamil.simple.app.activity;

import android.test.AndroidTestCase;
import orlowski.kamil.simple.app.adapter.CountryListAdapter;
import orlowski.kamil.simple.app.domain.Country;
import orlowski.kamil.simple.app.R;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by Kamil on 2014-10-19.
 * Adapter Tests
 */
public class CountryListAdapterTests extends AndroidTestCase {
    private CountryListAdapter adapter;

    public CountryListAdapterTests() {
        super();
    }

    /**
     * Tworze Stub, który służy do wypełnienia adaptera
     * @throws Exception
     */
    @Override
    public void setUp() throws Exception {
        super.setUp();
        List<Country> data = new LinkedList<>();
        data.add(new Country("pl", "Polska", R.drawable.pl, 1));
        data.add(new Country("gb", "Wielka Brytania", R.drawable.gb, 2));
        adapter = new CountryListAdapter(getContext(), android.R.layout.simple_list_item_1, data);
    }

    /**
     * Testowanie pobierania elementów z adaptera
     * @throws Exception
     */
    public void testGetItem() throws Exception {
        assertEquals("Polska was expected", "Polska", adapter.getItem(0).getCountryName());
        assertEquals("Wielka Brytania was expected", "Wielka Brytania", adapter.getItem(1).getCountryName());
        assertEquals("pl was expected", "pl", adapter.getItem(0).getCountryCode());
        assertEquals("gb was expected", "gb", adapter.getItem(1).getCountryCode());
        assertEquals(R.drawable.pl, adapter.getItem(0).getImagePath());
        assertEquals(R.drawable.gb, adapter.getItem(1).getImagePath());
    }

    /**
     * Testowanie, który sprawdza rozmiar adaptera
     */
    public void testGetCount() {
        assertEquals("Country amount incorrect.", 2, adapter.getCount());
    }
}
